package com.dengc.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dengc.springboot.common.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import com.dengc.springboot.service.IDictService;
import com.dengc.springboot.entity.Dict;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dengc
 * @since 2023-04-27
 */
@RestController
@RequestMapping("/dict")
public class DictController {

        @Resource
        private IDictService dictService;

        @PostMapping
        public Result save(@RequestBody Dict dict) {
            return Result.success(dictService.saveOrUpdate(dict));
        }

        @DeleteMapping("/{id}")
        public Result delete(@PathVariable Integer id) {
            return Result.success(dictService.removeById(id));
        }

        @GetMapping
        public Result findAll() {
            return Result.success(dictService.list());
        }

        @GetMapping("/{id}")
        public Result findOne(@PathVariable Integer id) {
            return Result.success(dictService.getById(id));
        }

        //批量删除
        @PostMapping("/del/batch")
        public Result deleteBatch(@RequestBody List<Integer> ids){
                return Result.success(dictService.removeByIds(ids));
        }

        @GetMapping("/page")
        public Result findPage(@RequestParam Integer pageNum,
                               @RequestParam Integer pageSize) {
                LambdaQueryWrapper<Dict> queryWrapper=new LambdaQueryWrapper<>();
                return Result.success(dictService.page(new Page<>(pageNum, pageSize),queryWrapper));
        }
}
